<?php 
/**
 * Yjnic_Cache cache
 *
 * @package     Yjnic
 * @author      prettyyjnic <prettyyjnic@qq.com> 2015-11-27
 */

class Yjnic_Cache{

    static protected $_cache_ins = array();

    private function __construct(){}

    static public function getCacheIns($config){
        if (empty($config)) {
            throw new Yjnic_Exception("Cache configs can not be empty", 501);
        }
        $key = serialize($config);
        if (isset(self::$_cache_ins[$key])) {
            return self::$_cache_ins[$key];
        }
        if (IS_SAE) {
            self::$_cache_ins[$key] = new Yjnic_Sae_Cache($config);
        }else{
            switch ($config['type']) {
                case 'memcache':
                case 'Memcache':
                    self::$_cache_ins[$key] = new PhalApi_Cache_Memcache($config);
                    break;
                case 'memcached':
                case 'Memcached':
                    self::$_cache_ins[$key] = new PhalApi_Cache_Memcached($config);
                    break;
                case 'none':
                case 'None':
                    self::$_cache_ins[$key] = new PhalApi_Cache_None($config);
                    break;
                case 'redis':
                case 'Redis':
                    self::$_cache_ins[$key] = new PhalApi_Cache_Redis($config);
                    break;
                default://默认文件缓存
                    self::$_cache_ins[$key] = new PhalApi_Cache_File($config);
                    
                    break;
            }
            
        }
        return self::$_cache_ins[$key];
    }
}